# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=totem-pl-parser
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.26.3
pkgrel=1
arch=('any')
pkgdesc="Simple GObject-based library to parse and save a host of playlist formats (mingw-w64)"
options=(strip staticlibs)
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gmime"
         "${MINGW_PACKAGE_PREFIX}-libsoup"
         "${MINGW_PACKAGE_PREFIX}-libarchive"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "gtk-doc")
license=("LGPL 2")
url="https://www.gnome.org"
source=(https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
        001-win.patch)
sha256sums=('0efd01b8a0a9770d52fe7354d298874ed845449b88f3f78f49290729fc2d448d'
            '370eabf2ec0b4d8182e4e5a474c0b63665bc278343243b6ad59f20dc94723771')
noextract=(${_realname}-${pkgver}.tar.xz)

prepare() {
  tar --exclude=really-flv.mp4 -Jxf ${_realname}-${pkgver}.tar.xz

  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-win.patch
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  ${MINGW_PREFIX}/bin/meson \
    --buildtype plain \
    -Dwith_introspection=false \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR=${pkgdir}${MINGW_PREFIX} ${MINGW_PREFIX}/bin/ninja install

  local _PRE_WIN="$(cygpath -m ${MINGW_PREFIX})"
  sed -e "s|${_PRE_WIN}|${MINGW_PREFIX}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/totem-plparser.pc \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/totem-plparser-mini.pc

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB"
}
